﻿
 //获取当前日期时间
var now = new Date();
var year = now.getFullYear();
var month = ("0" + (now.getMonth() + 1)).slice(-2);
var day = ("0" + now.getDate()).slice(-2);
var hours = ("0" + now.getHours()).slice(-2);
var minutes = ("0" + now.getMinutes()).slice(-2);
//var seconds = ("0" + now.getSeconds()).slice(-2);
var serialNumber = year+"-"+ month+"-" + day+" " + hours+":" + minutes;

//反填

$(function () {
    fantian1();
    
})
//反填采购消息
function fantian1() {
    // 发送AJAX请求获取数据
    console.log(localStorage.getItem("purchaseID"))
            $.ajax({
                type: "get",
                url: "/Purch/FabPurch",
                data: {
                    PurchaseID: localStorage.getItem("purchaseID"),
                    token: localStorage.getItem("token")
                },
                success: function (res) {
                    var ter = JSON.parse(res)
                    console.log(ter.data)

                    $(ter.data).each(function () {
                        $('#purchaseCode').val(this.purchaseCode);
                        $('#ingredient').val(this.ingredientnumber);
                        $('#ingredientName').val(this.ingredientName);
                        $('#purchaseNumber').val(this.purchaseNumber);
                        $("[name='purchaseSpecification'][value='" + this.purchaseSpecification + "']").prop("checked", true);
                        $("[name='purchaseSize'][value='" + this.purchaseSize + "']").prop("checked", true);
                        $('#purchaseDate').val(this.purchaseDate.substring(0,10));
                        $('#purchaseBudget').val(this.purchaseBudget);
                        $('#purchaseBatch').val(this.purchaseBatch);

                    })
                  
                },
               
            });
         
    
}
//修改采购信息
var obj1 = {
    "createdBy": "",
    "createdDate": "",
    "updatedBy": "",
    "updatedDate": "",
    "deletedBy": "",
    "deletedDate": "",
    "purchaseID": "",
    "purchaseCode": "",
    "ingredientnumber": "",
    "ingredientName": "",
    "purchaseNumber": "",
    "purchaseSpecification": "",
    "purchaseSize": "",
    "purchaseDate": "",
    "purchaseBudget": "",
    "purchaseBatch": "",
    "purchaseSart": "",
    "purchaseSumMoney": "",
    "purchasePrice": "",
    "purchasePayPrice": "",
    "payType": ""
};
layui.use(function () {
    var $ = layui.$;
    var layer = layui.layer;
    var util = layui.util;
    var form = layui.form;
    var table = layui.table;

    //修改采购信息
    form.on('submit(formSubmit)', function (data) {
        var field = data.field;
        var checkStatus = table.checkStatus('UpdatessPurch');
        field.allocationProdutesList = checkStatus.data.map(function (item) {
            return item;
        });
        console.log(field)
        obj1.purchaseID = localStorage.getItem("purchaseID")
        obj1.purchaseCode = field.purchaseCode
        obj1.ingredientnumber = field.ingredient
        obj1.ingredientName = field.ingredientName
        obj1.purchaseNumber = field.purchaseNumber
        obj1.purchaseSpecification = field.purchaseSpecification
        obj1.purchaseSize = field.purchaseSize
        obj1.purchaseDate = field.purchaseDate
        obj1.purchaseBudget = field.purchaseBudget
        obj1.purchaseBatch = field.purchaseBatch
        obj1.updatedBy = ""
        obj1.updatedDate = serialNumber
        obj1.purchaseSart ="待采购"
        console.log(obj1);//field.products
        // 显示填写结果，仅作演示用
        $.ajax({
            url: '../Purch/GetUpdatePruch',
            type: 'post',
            data: {
                field: obj1,
                token: localStorage.getItem("token"),
            },
            success: function (res) {
                var res = JSON.parse(res)
                console.log(obj1);
                console.log(res);
                if (res.code > 0) {
                    layer.alert("修改成功");
                    location.href = '/Purch/ShowPurch'
                } else {
                    layer.alert("修改失败");
                }
            }
        });

        return false; // 阻止默认 form 跳转
    });

});



